package com.test.views.ui;

import com.test.R;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class IndicatorView extends LinearLayout {

	private Context mContext;
    private int currentIndex = -1;
    private boolean isinited = false;

	public IndicatorView(Context c) {
		super(c);
		this.mContext = c;
//		initView(3);
	}

	public IndicatorView(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.mContext = context;
//		initView(3);
	}
	
	
	
	public void initView(int count) {
		this.removeAllViews();
		for(int i=0;i<count;i++ ){
		ImageView imageView = new ImageView(mContext);
		imageView.setBackgroundResource(R.drawable.display_point);
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
		lp.leftMargin = 5;
		lp.rightMargin = 5;
		addView(imageView,lp);
		if(count>0){
			setItemSelected(0);	
		}
//		((LinearLayout.LayoutParams)imageView.getLayoutParams()).topMargin = UiTools.dip2px(mContext, 5);
		}
	}


	
	public void setItemSelected(int index){
		if(index>=this.getChildCount()){
		}else if(currentIndex!=index){
			if(currentIndex>-1){
			this.getChildAt(currentIndex).setSelected(false);
			}
			currentIndex = index;
			this.getChildAt(index).setSelected(true);
		}
	}
}